package com.chinasoft.Config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;

import javax.sql.DataSource;

public class MybatisConfig {

    @Bean
    public SqlSessionFactoryBean getSqlSessionFactory(@Autowired DataSource dataSource){
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
        ssfb.setDataSource(dataSource);
        ssfb.setTypeAliasesPackage("com.chinasoft.pojo");
        // 让 factory 对象读取 配置文件
        // 让驼峰命名生效
        ssfb.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
        return ssfb;
    }
    @Bean
    public MapperScannerConfigurer getMapperScannerConfig(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.chinasoft.mapper");
        return msc;
    }
}
